<?php

namespace App\Http\Middleware;

use Closure;

class RecordMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        //获取IP
        $ip = $request -> ip();
        //时间戳
        $time = date("Y-m-d H:i:s");

        $agent = $request -> header('user-agent');
        //记录  将请求写入到日志
        file_put_contents('./log.txt',$ip." --- ".$time." --- ".$agent."\r\n",FILE_APPEND);
        return $next($request);

    }
}
